﻿using System;
using ApplicationLibrary;
using ApplicationLibrary.DBManager;
using ApplicationLibrary.ExtendedControls;
using Plumber.Sales.Forms;
using Plumber.Sales.ModuleData;

namespace Plumber.Sales.Library
{
    internal class SalesInvoiceCreator : IDocumentDataManager, IDisposable
    {
        private SalesInvoice si = null;

        public SalesInvoiceCreator()
        {
            si = (SalesInvoice)GlobalInfo.OpenDataManager("Plumber.Plumber.Sales.Forms.SalesInvoice");
            si.ShowDialog(false);
            si.SilentMode = true;
        }

        public bool AddNew()
        {
            return si.ToolbarEvent(DocumentForm.ToolbarEventKind.New);
        }

        public bool Edit()
        {
            return si.ToolbarEvent(DocumentForm.ToolbarEventKind.Edit);
        }

        public bool Save()
        {
            return si.ToolbarEvent(DocumentForm.ToolbarEventKind.Save);
        }

        public bool Delete()
        {
            return si.ToolbarEvent(DocumentForm.ToolbarEventKind.Delete);
        }

        public bool Find(IRadarParameters key)
        {
            return si.FindRecord(key);
        }

        public bool Find(string saleNo)
        {
            RadarSaleInvoicesParam param = new RadarSaleInvoicesParam(saleNo);
            return Find(param);
        }

        public void Dispose()
        {
            si.Close();
            si.Dispose();
            si = null;
        }
    }
}